package com.liqi.web.controller.statistics;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.liqi.statistics.domain.DvServiceStatistics;
import com.liqi.statistics.domain.dto.ItemStatisticsDto;
import com.liqi.statistics.module.ItemStatisticsModule;
import com.liqi.statistics.service.DvServiceTimeService;
import com.liqi.statistics.service.IDvServiceStatisticsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.page.TableDataInfo;
import com.liqi.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 统计Controller
 *
 * @author admin
 * @date 2022-11-05
 */
@Api(tags = "统计接口")
@RestController
@RequestMapping("/statistics/")
public class StatisticsController extends BaseController
{


    @Autowired
    private DvServiceTimeService dvServiceTimeService;
    @Autowired
    private IDvServiceStatisticsService dvServiceStatisticsService;


    /**
     * 投放情况以及运行状况统计
     */
    @ApiOperation("投放情况以及运行状况统计")
    @GetMapping("/deploymentRun")
    public TableDataInfo deploymentRun(DvServiceStatistics dvServiceStatistics)
    {
        startPage();
        List<DvServiceStatistics> list = dvServiceStatisticsService.selectDvServiceStatisticsList(dvServiceStatistics);
        return getDataTable(list);
    }

    /**
     * 导出投放情况以及运行状况统计
     */
    @ApiOperation("导出投放情况以及运行状况统计")
    @PostMapping("/exportDeploymentRun")
    public void exportDeploymentRun(HttpServletResponse response, DvServiceStatistics dvServiceStatistics)
    {
        List<DvServiceStatistics> list = dvServiceStatisticsService.selectDvServiceStatisticsList(dvServiceStatistics);
        ExcelUtil<DvServiceStatistics> util = new ExcelUtil<DvServiceStatistics>(DvServiceStatistics.class);
        util.exportExcel(response, list, "投放情况以及运行状况统计");
    }


    /**
     * 使用效率统计
     */
    @ApiOperation("使用效率统计")
    @GetMapping("/useRate")
    public TableDataInfo useRate(DvServiceStatistics dvServiceStatistics)
    {
        startPage();
        List<DvServiceStatistics> list = dvServiceStatisticsService.selectDvServiceStatisticsList(dvServiceStatistics);
        return getDataTable(list);
    }

    /**
     * 导出使用效率统计
     */
    @ApiOperation("导出使用效率统计")
    @PostMapping("/exportUseRate")
    public void exportUseRate(HttpServletResponse response, DvServiceStatistics dvServiceStatistics)
    {
        List<DvServiceStatistics> list = dvServiceStatisticsService.selectDvServiceStatisticsList(dvServiceStatistics);
        ExcelUtil<DvServiceStatistics> util = new ExcelUtil<DvServiceStatistics>(DvServiceStatistics.class);
        util.exportExcel(response, list, "投放情况以及运行状况统计");
    }


    /**
     * 使用频率统计
     */
    @ApiOperation("使用频率统计")
    @GetMapping("/useFrequency")
    public TableDataInfo useFrequency(DvServiceStatistics dvServiceStatistics)
    {
        startPage();
        List<DvServiceStatistics> list = dvServiceStatisticsService.selectDvServiceFrequencyStatisticsList(dvServiceStatistics);
        return getDataTable(list);
    }

    /**
     * 导出使用效率统计
     */
    @ApiOperation("导出使用频率统计")
    @PostMapping("/exportUseFrequency")
    public void exportUseFrequency(HttpServletResponse response, DvServiceStatistics dvServiceStatistics)
    {
        List<DvServiceStatistics> list = dvServiceStatisticsService.selectDvServiceStatisticsList(dvServiceStatistics);
        ExcelUtil<DvServiceStatistics> util = new ExcelUtil<DvServiceStatistics>(DvServiceStatistics.class);
        util.exportExcel(response, list, "投放情况以及运行状况统计");
    }

    /**
     * 使用频率统计
     */
    @ApiOperation("使用频率统计,这个才是")
    @GetMapping("/useFrequencyTow")
    public TableDataInfo useFrequencyTow(ItemStatisticsDto dto)
    {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<ItemStatisticsModule> list = dvServiceTimeService.useFrequencyTow(dto);
        return getDataTable(list);
    }
    /**
     * 导出使用效率统计
     */
    @ApiOperation("导出使用效率统计2023-02-01")
    @PostMapping("/exportUseFrequencyTow")
    public void exportUseFrequencyTow(HttpServletResponse response, ItemStatisticsDto dto)
    {
        List<ItemStatisticsModule> list = dvServiceTimeService.useFrequencyTow(dto);
        ExcelUtil<ItemStatisticsModule> util = new ExcelUtil<ItemStatisticsModule>(ItemStatisticsModule.class);
        util.exportExcel(response, list, "使用效率统计");
    }
}
